<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>海角论坛</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="keywords" content="fly,layui,前端社区">
    <meta name="description" content="Fly社区是模块化前端UI框架Layui的官网社区，致力于为web开发提供强劲动力">
    <link rel="stylesheet" href="../../static/res/layui/css/layui.css">
    <link rel="stylesheet" href="../../static/res/css/global.css">
</head>
<body>
<meta name="referrer" content="no-referrer">
<div class="fly-header layui-bg-black">
    <div class="layui-container">
        <a class="fly-logo" href="/">
            <img src="../../static/res/images/logo.png" alt="layui">
        </a>

        <ul class="layui-nav fly-nav-user" id="ul_user">

            <!-- 登入后的状态 -->
            {%if user%}
            <li class="layui-nav-item">
              <a class="fly-nav-avatar" href="javascript:;">
                <cite class="layui-hide-xs">{{user.nick_name}}</cite>
                <i class="iconfont icon-renzheng layui-hide-xs" title="认证信息：南神"></i>
                  {%if user.is_vip != 0%}
                <i class="layui-badge fly-badge-vip layui-hide-xs">VIP{{user.is_vip}}</i>
                  {%endif%}
                <img src="{{user.avatar_url}}">
              </a>
              <dl class="layui-nav-child">
                <dd><a href="/user/set"><i class="layui-icon">&#xe620;</i>基本设置</a></dd>
                <dd><a href="/user/follow"><i class="iconfont icon-tongzhi" style="top: 4px;"></i>我的关注</a></dd>
                <dd><a href="/user/home?u={{user.id}}"><i class="layui-icon" style="margin-left: 2px; font-size: 22px;">&#xe68e;</i>我的主页</a></dd>
                <hr style="margin: 5px 0;">
                <dd><a href="/user/logout" style="text-align: center;">退出</a></dd>
              </dl>
            </li>
            {%else%}
                        <!-- 未登入的状态 -->
            <li class="layui-nav-item">
                <a class="iconfont icon-touxiang layui-hide-xs" href="/login"></a>
            </li>
            <li class="layui-nav-item">
                <a href="/login">登录</a>
            </li>
            <li class="layui-nav-item">
                <a href="/reg">注册</a>
            </li>
            {%endif%}
        </ul>
    </div>
</div>

<div class="layui-hide-xs">
    <div class="fly-panel fly-column">
        <div class="layui-container">
            <ul class="layui-clear">
                <li class="layui-hide-xs"><a href="/">首页</a></li>
                <li ><a href="/zt?are=tw">提问</a></li>
                <li><a href="/zt?are=fx">分享<span></span></a></li>
                <li><a href="/zt?are=tl">讨论</a></li>
                <li class="layui-hide-xs layui-hide-sm layui-show-md-inline-block"><span class="fly-mid"></span></li>


                <li class="layui-hide-xs layui-hide-sm layui-show-md-inline-block"><a
                        href="/user/user_message#index">我发表的贴</a></li>
                <li class="layui-hide-xs layui-hide-sm layui-show-md-inline-block"><a
                        href="/user/collect">我收藏的贴</a></li>
            </ul>

            <div class="fly-column-right layui-hide-xs">
                <a href="/user/add" class="layui-btn">发表新帖</a>
            </div>
            <div class="layui-hide-sm layui-show-xs-block"
                 style="margin-top: -10px; padding-bottom: 10px; text-align: center;">
                <a href="/user/add" class="layui-btn">发表新帖</a>
            </div>
        </div>
    </div>
</div>

<div class="layui-container">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md8 content detail">
            <div class="fly-panel detail-box">
                <h1>{{tie.title}}</h1>
                <div class="fly-detail-info">
                    <!-- <span class="layui-badge">审核中</span> -->
                    <span class="layui-badge layui-bg-green fly-detail-column">{{tie.category.name}}</span>

                    <div class="fly-admin-box" data-id="123">
                    </div>
                    <span class="fly-list-nums">
            <a href="#comment"><i class="iconfont" title="回答">&#xe60c;</i> {{tie.comment_num}}</a>
            <i class="iconfont" title="人气">&#xe60b;</i> {{tie.clicks}}
          </span>
                </div>
                <div class="detail-about">
                    <a class="fly-avatar" href="/user/home?u={{tie.user.id}}">
                        <img src="{{tie.user.avatar_url}}"
                             alt="{{tie.user.nick_name}}">
                    </a>
                    <div class="fly-detail-user">
                        <a href="/user/home?u={{tie.user.id}}" class="fly-link">
                            <cite>{{tie.user.nick_name}}</cite>
                            {% if tie.user.is_vip != 0%}
                            <i class="layui-badge fly-badge-vip">VIP{{tie.is_vip}}</i>
                            {% endif %}

                        </a>
                        <span>{{tie.update_time}}</span>
                    </div>
                    <div class="detail-hits" id="LAY_jieAdmin" data-id="123">
                        <span style="padding-right: 10px; color: #FF7200">悬赏：{{tie.award}}飞吻</span>
<!--?                        当用户已经登录了并且这个帖子是他的时候才显示编辑-->
<!--?                        <span class="layui-btn layui-btn-xs jie-admin" type="edit"><a href="add.html">编辑</a></span>-->
                        {%if not coll%}
                        <span class="layui-btn layui-btn-xs jie-admin" type="edit"><a  onclick="shoc({{tie.id}})">收藏</a></span>
                         <input type="hidden" id="sc" value="do">
                        {%else%}
                        <span class="layui-btn jie-admin" type="edit"><a  onclick="shoc({{tie.id}})">已收藏</a></span>
                        <input type="hidden" id="sc" value="undo">
                        {%endif%}
                    </div>

                    <li value="{{tie.id}}" class="comment_input" id="tie_id"></li>
                </div>
                {{tie.content | safe}}
            </div>

            <div class="fly-panel detail-box" id="flyReply">
                <fieldset class="layui-elem-field layui-field-title" style="text-align: center;">
                    <legend>回帖</legend>
                </fieldset>

                <ul class="jieda" id="jieda">

                    {%for i in comment.items%}
                    <li data-id="111">
                        <a name="item-1111111111"></a>
                        <div class="detail-about detail-about-reply">
                            <a class="fly-avatar" href="/user/home?u={{i.user.id}}">
                                <img src="{{i.user.avatar_url}}"
                                     alt=" ">
                            </a>
                            <div class="fly-detail-user">
                                <a href="/user/home?u={{i.user.id}}" class="fly-link">
                                    <cite>{{i.user.nick_name}}</cite>
                                </a>
                            </div>
                            <div class="detail-hits">
                                <span>{{i.create_time}}</span>
                            </div>
                        </div>
                        <div class="detail-body jieda-body photos">
                            {%if i.hf %}
                            <p>回复<a href="/user/home?u={{i.hf.user.id}}">{{i.hf.user.nick_name}}</a>的评论：{{i.hf.content | safe}}</p>
                            {%endif%}
                            {{i.content | safe}}
                        </div>
                        <div class="jieda-reply comment_list_con">
              <span class="jieda-zan" type="zan">
                <i class="iconfont icon-zan"></i>
                <em>0</em>
              </span><i class="iconfont icon-svgmoban53"></i>
              <a href="javascript:;" class="comment_reply" id="diji{{loop.index}}">回复</a>
                   <from class="reply_form" >
                     <div class="layui-form layui-form-pane">

                        <div class="layui-form-item layui-form-text">
                            <a name="comment"></a>
                            <div class="layui-input-block">
                                <textarea id="L_content{{loop.index}}" name="content" required lay-verify="required"
                                          placeholder="请输入要回复的内容" class="layui-textarea fly-editor"
                                          style="height: 150px;"></textarea>
                                <input id="reply_id{{loop.index}}" value="{{i.id}}" hidden>
                                <button class="layui-btn"  onclick="aaa({{loop.index}})" id="comment_form" data-news-id="{{tie.id}}">提交回复</button>
                                <button class="layui-btn fr" onclick="dianji({{loop.index}})">取消</button>

                            </div>
                        </div>
                </div>
                </from>
                            </div>
                    </li>
                    {%endfor%}
                    {%if not comment.items%}
                        <li class="fly-none">消灭零回复</li>
                    {%endif%}
                </ul>

                <div class="layui-form layui-form-pane">
             <form action="">
                        <div class="layui-form-item layui-form-text">
                            <a name="comment"></a>
                            <div class="layui-input-block">
                                <textarea id="L_content111" name="content" required lay-verify="required"
                                          placeholder="请输入内容" class="layui-textarea fly-editor"
                                          style="height: 150px;"></textarea>
                                <input id="reply_id111" value="None" hidden>
                                <input class="layui-btn fr" onclick="aaa(111)" style="width:120px;" value="提交" readonly>
                            </div>

                        </div>
                        <div>
                            <input type="hidden" name="jid" value="123">
</div></form>
                </div></div>

                    <div style="margin-left: 18%">
            <div style="border-top: 1px dotted #e2e2e2">
            <div class="laypage-main" style="margin-left:-20%">
                {%if comment.page != 1%}
                <a href="/detail/{{tie.id}}?page=1" class="laypage-last" title="首页">首页</a>
                {%endif%}
                {%if comment.has_prev%}
                <a href="/detail/{{tie.id}}?page={{comment.prev_num}}" class="laypage-prev">上一页</a>
                {%endif%}
                 <span class="laypage-curr">{{comment.page}}</span>
                {%if comment.page + 1 <= comment.pages%}
                <a href="/detail/{{tie.id}}?page={{comment.page + 1}}">{{comment.page + 1}}</a>
                {%endif%}
                  {%if comment.page + 2 <= comment.pages%}
                <a href="/detail/{{tie.id}}?page={{comment.page + 2}}">{{comment.page + 2}}</a>
                {%endif%}
                {%if comment.page + 3 <= comment.pages%}
                <a href="/detail/{{tie.id}}?page={{comment.page + 3}}">{{comment.page + 3}}</a>
                {%endif%}
                  <span>…</span>
                  <a href="/detail/{{tie.id}}?page={{comment.pages}}" class="laypage-last" title="尾页">尾页</a>
                {%if comment.has_next%}
                 <a href="/detail/{{tie.id}}?page={{comment.next_num}}" class="laypage-next">下一页</a>
                {%endif%}
             </div></div></div>


        </div>



    </div>
</div>

<div class="fly-footer">
    <p><a href="#">海角论坛</a> 2019 &copy; <a href="#">葫芦娃出品</a></p>
</div>

<script src="../../static/json/jquery-3.3.1.min.js"></script>
<script src="../../static/js/jquery-3.3.1.js"></script>
<script src="../../static/res/layui/layui.js"></script>
<script src="../../static/js/jwt.js"></script>
<script src="../../static/res/mods/detail.js"></script>
<script>
    $(function () {
        hasUser();

    });

    function hasUser(){

        let jwt = getJwtToken();
        if (jwt) {
            $.ajax({
                type:"get",
                url: HOST_URL + "user/getUser",
                dataType: "json",
                headers: createAuthorizationTokenHeader(),
                success:function (data) {
                    console.log(data);
                    if (data) {
                        let appendVal = `
                            <li class="layui-nav-item">
                              <a class="fly-nav-avatar" href="javascript:;">
                                <cite class="layui-hide-xs">${data.username}</cite>
<!--                                <i class="iconfont icon-renzheng layui-hide-xs" title="认证信息：layui 作者"></i>-->
                                <i class="layui-badge fly-badge-vip layui-hide-xs">VIP${data.level}</i>
                                <img src="${data.picture}">
                              </a>
                              <dl class="layui-nav-child">
                                <dd><a href="../user/set.html"><i class="layui-icon">&#xe620;</i>基本设置</a></dd>
                                <dd><a href="../user/message.html"><i class="iconfont icon-tongzhi" style="top: 4px;"></i>我的消息</a></dd>
                                <dd><a href="../user/home.html"><i class="layui-icon" style="margin-left: 2px; font-size: 22px;">&#xe68e;</i>我的主页</a></dd>
                                <hr style="margin: 5px 0;">
                                <dd><a href="javascript:logout();" style="text-align: center;">退出</a></dd>
                              </dl>
                            </li>
                        `;

                        $("#ul_user").html(appendVal);
                    }
                }
            })
        }
    }
    //  注销
    function logout() {
        layer.confirm("真的要注销吗?", () => {

            removeJwtToken();
            layer.msg("注销成功", {time: 1000}, function () {
                location.reload();
            });
        })
    }
    function dianji(e) {
        document.getElementById("diji" + e).click()
    }

    function aaa(e) {
		var content= document.getElementById("L_content" + e).value;
        var reply_id = document.getElementById("reply_id" + e).value;   // 获取这条评论回复的是谁的评论
        var news_id = document.getElementById("tie_id").value;
		if (!content) {
            //如果回复的内容没有数据则弹窗
            alert("你还没有评论。。。。");
            return;
        }
        var params = {
            "content": content,
            "reply_id": reply_id,
            "news_id": news_id};

		$.ajax({
            url: "/user/reply",
            type: "post",
            data: JSON.stringify(params),
            contentType: "application/json",
            success: function (resp) {
            if (resp.errno == "0") {
                   location=location
                }
                else if (resp.errno == "8009"){
                    alert(resp.msg)
                    location.href="/login"
                }
                else if (resp.errno == "9006"){
                    alert(resp.msg)
                    location.href="/user/index"
                }
                else {
                    alert(resp.msg)
                }
            }
        })
    }
    function shoc(e) {
    var zl = document.getElementById("sc").value;
        var params = {
            "zl": zl,
            "news_id": e
        };
        $.ajax({
            url: "/user/collect",
            type: "post",
            data: JSON.stringify(params),
            contentType: "application/json",
            success: function (resp) {
                if (resp.errno == "0") {
                   location=location
                }
                else {
                    alert(resp.msg)
                }
    }})
    }
</script>

</body>
</html>